/*
 * mibTree.h
 *
 *  Created on: 2011-7-6
 *      Author: fufan
 */

#ifndef MIBTREE_H_
#define MIBTREE_H_
#include "ui_QSnmp.h"
#include "ui_Set.h"
#include "ui_SelectInstance.h"
#include "ui_PromptInstance.h"
#include "mibTreeModel.h"
#include "setDialog.h"
#include "agent.h"
#include "snmp_pp/snmp_pp.h"
#include <QTreeView>
#include <QSettings>
#include <QTextEdit>
#include <QTextCodec>
#include <QTimer>
#include <QtGui>

#define ASYNC_RECV 50


class MibTree : public QObject
{
	Q_OBJECT
public:
	MibTree(Ui::MainWindow *mainGui);
	~MibTree();
	void asyncGet(int reason, Pdu &pdu);
	void asyncGetNext(int reason, Pdu &pdu);
	void asyncGetBulk(int reason, Pdu &pdu);
	void asyncWalk(int reason, SnmpTarget &target, Pdu &pdu);

public slots:
	void setValue(const QString &instance, const QString &value);

private slots:
	void displayNodeInfo(const QModelIndex &index);
	void callSettingDialog();
	void readSettings(const QString &text);
	void expand();
	void collapse();
	void timeToRecv();

	void get();
	void getNext();
 	void getBulk();
 	void walk();
 	void stop();
	void set();
	void displayTableView();
	void instanceItem(QListWidgetItem *item);
	void promptItem(const QString &text);
	void getItem();
	void getSelectItem();
	void getPromptItem();
	void noInstanceItem();
	void nextSelectItem();
	void nextPromptItem();
	void getBulkSelectItem();
	void getBulkPromptItem();
	void createMenu(const QPoint &pos);

	void clearResult();
	void displaySaveDialog();
	void saveResponse(const QString &path);
	void createTextMenu(const QPoint &pos);
	void displayResponse(const QString &response);

signals:
	void responseString(const QString &response);

private:
	void expandTree(const QModelIndex &index);
	void collapseTree(const QModelIndex &index);
	void initialBeforeSend(QString &qOid, Pdu &pdu);
	void showSelectItem();
	void showPromptItem();
	QString setValueColor(const QString &value, const QString &color);
	MibItem*  searchName(MibItem *item, const QString &qOid);
	void printError(const QString &error);

private:
	QTreeView *treeView;
	QTextEdit *nodeTextEdit;
	QTextEdit *resultTextEdit;
	QRadioButton *snmp1;
	QRadioButton *snmp2;
	QPushButton *agentBtn;
	QComboBox *agentBox;
	QList<QString> title;
	int count;
	bool isWalk;
	string originOid;
	QTimer timer;
	Snmp *snmp;
	CTarget *ctarget;

};



#endif /* MIBTREE_H_ */
